package com.pengcheng.taskapplication.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.pengcheng.taskapplication.R;
import com.pengcheng.taskapplication.model.CarModel;
import com.pengcheng.taskapplication.model.SubscribeOrderListModel;

import java.util.List;

public class CarAdapter extends BaseAdapter {

	Context context;
	LayoutInflater inflater;
	List<CarModel> carModels;
	int last_item;
	private int selectedPosition = -1;
	public CarAdapter(Context context, List<CarModel> carModels){
		this.context = context;
		this.carModels = carModels;
		inflater= LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return carModels.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return carModels.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder  holder = null;
		if(convertView==null){
			convertView = inflater.inflate(R.layout.activity_car_item_layout, null);
			holder = new ViewHolder();
			holder.tv_plate =(TextView)convertView.findViewById(R.id.tv_plate);
			holder.tv_owner=(TextView)convertView.findViewById(R.id.tv_owner);
			holder.tv_plate_no=(TextView)convertView.findViewById(R.id.tv_plate_no);
			convertView.setTag(holder);
		}
		else{
			holder=(ViewHolder)convertView.getTag();
		}

		CarModel model= carModels.get(position);
		holder.tv_plate.setText(model.getEcardCode());
		holder.tv_owner.setText("张云");
		holder.tv_plate_no.setText("车牌: "+model.getPlateNo());

		return convertView;
	}

	public static class ViewHolder{
		public TextView tv_plate;
		public TextView tv_owner;
		public TextView tv_plate_no;

	}

	public void setSelectedPosition(int position) {
		selectedPosition = position;
	}

}
